



/************************************/
/*                                  */ 
/* Add additional family variables  */
/*                                  */ 
/************************************/



libname raw 'G:\Data\Rawdata\707677';

libname common 'G:\Data\Workdata\707677\Common\01Data\01SAS';




/*******************/
/* Load our sample */
/*******************/



data panel;

set common.panel;

keep pnr aar antboernf antpersf;

run;





/******************/
/* Data from fain */
/******************/



data fain;

set raw.fain;

keep pnr aar civst d_familie_id;

run;



data fain;

set fain;

new_aar=input(aar, 4.);

run;



data fain;

set fain;

drop aar;

rename new_aar=aar;

run;



proc datasets library=work nolist;

modify fain;

attrib _all_ label='';

quit;




proc sql;

create table panel as select *

from panel as a left join

fain as b on

a.pnr=b.pnr and 

a.aar=b.aar;

quit;



data fain;

set fain;

keep aar d_familie_id adder;

adder=1;

run;



proc sort data=fain;

by aar d_familie_id;

run;



proc summary data=fain;

by aar d_familie_id;

output out=stats

n(adder)=antpersf_d;

run;



data stats;

set stats;

drop _type_ _freq_;

run;




proc sql;

create table panel as select *

from panel as a left join

stats as b on

a.d_familie_id=b.d_familie_id and 

a.aar=b.aar;

quit;




proc sort data=panel; 

by pnr aar; 

run;





data panel_merge;

set panel;

keep pnr aar antpersf_d;

run;





data panel;

set common.panel;

run;





proc sql;

create table panel as select *

from panel as a left join

panel_merge as b on

a.pnr=b.pnr and 

a.aar=b.aar;

quit;






proc sort data=panel nodupkey;

by pnr aar;

run;





data common.panel;

set panel;

run;






proc datasets library=work nolist kill;

quit;



